﻿using System;
using System.Collections;
using System.Data;
using System.Web;
using System.Web.Services;
using System.Web.Services.Protocols;

namespace Rison.Web.login
{
    /// <summary>
    /// $codebehindclassname$ 的摘要说明
    /// </summary>
    [WebService(Namespace = "http://tempuri.org/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    public class api : IHttpHandler
    {

        public void ProcessRequest(HttpContext context)
        {

            context.Response.ContentType = "text/plain";
            string username = context.Request.Params["username"];
            string password = context.Request.Params["password"];
            string key = context.Request.Params["key"];
            if (!"ayKdseyyIsfuOpvj3wpzW098i".Equals(key))
            {
                context.Response.Write("false");
                return;
            }

            if (String.IsNullOrEmpty(username) || String.IsNullOrEmpty(password))
            {
                context.Response.Write("false");
            }
            else
            {
                object result = InvokeWebService(username, password);
                context.Response.Write(result.ToString().ToLower());
            }


        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }

        private object InvokeWebService(string username, string password)
        {
            string url = "http://authcenter.cn.gov/WebService/UserService.asmx";
            string method = "ValidateUser";
            //string url = "http://dept.changning.sh.cn/JFB.Gmail.AdminWeb/Mail/WebServices/SMS.asmx";
            //string method = "SendMessage";
            string[] args = new string[2];
            args[0] = username;
            args[1] = password;
            object result = DynamicWebServices.InvokeWebService(url, method, args);

            //result = "true"; //for test
            return result;
        }
    }
}
